//
//  SQLManager.swift
//  weibo
//
//  Created by lixin on 16/4/28.
//  Copyright © 2016年 lixin. All rights reserved.
//

import Foundation

//数据库名称
private let myNmae = "status.db"

class SQLManager {
    
    //全局访问点
    static let sharedTools: SQLManager = SQLManager()
    
    //定义全局的核心对象
    let queue: FMDatabaseQueue
    
    private init(){
    
       let path = (NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true).last! as NSString).stringByAppendingPathComponent(myNmae)
        
        queue = FMDatabaseQueue(path: path)
        
//        print(path)
        
        createTable()
    }
    
    func createTable(){
        
        let sql = "CREATE TABLE IF NOT EXISTS T_Status (" +
            "statusId integer PRIMARY KEY NOT NULL," +
            "status text," +
            "userId text) ;"
        
        queue.inDatabase { (db) -> Void in
            
            if db.executeStatements(sql) {
            
                print("创建数据库表成功")
            
            }else{
            
                print("创建数据库表失败")
            }
        }
    }
}
